package cc.messcat.web.fupin;

import cc.messcat.common.constant.CommonConstant;
import cc.messcat.common.constant.CommonRedisConstant;
import cc.messcat.common.model.Pager;
import cc.messcat.common.model.ResponseBean;
import cc.messcat.common.util.BeanUtil;
import cc.messcat.common.util.LogUtil;
import cc.messcat.entity.area.Area;
import cc.messcat.entity.fupin.Dequeue;
import cc.messcat.entity.fupin.PoorVillage;
import cc.messcat.entity.fupin.PoorVillageHistory;
import cc.messcat.entity.system.ApplicationProperties;
import cc.messcat.entity.system.McUser;
import cc.messcat.entity.system.TableMaintenance;
import cc.messcat.log.OperationLog;
import cc.messcat.service.area.AreaService;
import cc.messcat.service.fupin.DequeueService;
import cc.messcat.service.fupin.FamilyService;
import cc.messcat.service.fupin.PoorFamilyService;
import cc.messcat.service.fupin.PoorVillageService;
import cc.messcat.service.helpTeam.HelpTeamService;
import cc.messcat.service.helpunits.HelpunitsService;
import cc.messcat.service.system.UserService;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.*;

@Controller
@RequestMapping("/poorVi")
public class PoorVillageController {
	private static Logger log = LoggerFactory.getLogger(PoorVillageController.class);

	@Autowired
	private PoorVillageService poorVillageService;
	
	@Autowired
	private PoorFamilyService poorFamilyService;

	@Autowired
	private FamilyService familyService;
	
	@Autowired
	public UserService userService;

	@Autowired
	private DequeueService dequeueService;

	@Autowired
	private HelpunitsService helpunitsService;

	@Autowired
	private HelpTeamService helpTeamService;

    @Autowired
    private CacheManager manager;

    @Autowired
    private AreaService areaService;

    @Autowired
    private TableMaintenance tableMaintenance;
    
	/**
	 * 贫困村列表查询
	 */
	@OperationLog(desc = "贫困村列表查询", module = "扶贫对象管理")
	@RequestMapping("/queryPoorVillage")
	@ResponseBody
	public Object queryPoorVillage(Integer pageNo, Integer pageSize) {
		if (pageNo == null || pageNo < 1) {
			pageNo = 1;
		}
		if (pageSize == null || pageSize < 1) {
			pageSize = 10;
		}
		Pager pager = this.poorVillageService.getPager(pageNo, pageSize);
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, pager);
	}

	/**
	 * 自然村列表查询
	 */
	@OperationLog(desc = "自然村列表查询", module = "扶贫对象管理")
	@RequestMapping("/queryNaVillage")
	@ResponseBody
	public Object queryNaVillage(Integer pageNo, Integer pageSize) {
		if (pageNo == null || pageNo < 1) {
			pageNo = 1;
		}
		if (pageSize == null || pageSize < 1) {
			pageSize = 10;
		}
		Pager pager = this.poorVillageService.getNaPager(pageNo, pageSize);
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, pager);
	}

	/**
	 * 行政村条件查询
	 */
	// @OperationLog(desc = "行政村条件查询", module = "扶贫对象管理")
	@RequestMapping("/queryVillages")
	@ResponseBody
	public Object queryVillages(Integer pageNo, Integer pageSize, @Valid PoorVillage poorVillage, HttpServletRequest req) {
		if (pageNo == null || pageNo < 1) {
			pageNo = 1;
		}
		if (pageSize == null || pageSize < 1) {
			pageSize = 10;
		}
		McUser user = (McUser) req.getSession().getAttribute("user");
		Pager pager = this.poorVillageService.getVillagesByCondition(pageNo, pageSize, poorVillage, user);
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, pager);
	}

	/**
	 * 贫困村添加
	 */
	@OperationLog(desc = "贫困村添加", module = "扶贫对象管理")
	@RequestMapping("/addPoorVillage")
	@ResponseBody
	public Object addPoorVillage(@Valid PoorVillage poorVillage) {
		String annual = ApplicationProperties.getAnnual();
        Area area = poorVillage.getArea();
        poorVillage.setType("0");
		poorVillage.setIsDel("0");
		poorVillage.setStatus("0");
		poorVillage.setAnnual(annual);

		Long id = null;
		PoorVillage village = this.poorVillageService.getVillageByAreaIdWithClear(area.getId(),
			poorVillage.getAnnual());
		if (village != null) {
			if ("0".equals(village.getType()))
				return new ResponseBean(CommonConstant.SUCCESS_CODE_200, "该地区是贫困村");
			poorVillage.setId(village.getId());
			poorVillage.setHelpPerunit(village.getHelpPerunit());
			poorVillage.setAddTime(village.getAddTime());
			poorVillage.setRoad(village.getRoad());
			poorVillage.setElectrics(village.getElectrics());
			poorVillage.setLifes(village.getLifes());
			poorVillage.setBroadbands(village.getBroadbands());
			poorVillage.setAnnual(village.getAnnual());
			poorVillage.setDistance(village.getDistance());
			poorVillageService.modifyPoorVillage(poorVillage);
			id = village.getId();
		} else {
			poorVillage.setAddTime(new Date());
            //贫困户数
            poorVillage.setPoor(ApplicationProperties.getPoorFamilyCount(annual,area.getId()));
            //贫困人口数
            poorVillage.setPoorNumber(ApplicationProperties.getFamilyCount(annual,area.getId()));
			id = poorVillageService.addPoorVillage(poorVillage);
		}

		Dequeue dequeue = new Dequeue();
		dequeue.setAnnual(annual);
		PoorVillageHistory poorVillageHistory = new PoorVillageHistory();
		BeanUtils.copyProperties(poorVillage, poorVillageHistory);
		poorVillageHistory.setOriginId(poorVillage.getId());
		dequeue.setPoorVillageHistory(poorVillageHistory);
		dequeue.setOriginPoorVillage(poorVillage);
		dequeue.setAddTime(new Date());
		dequeue.setChanges("2");// 贫困村新增
		poorVillageHistory.setId(null);
		poorVillageService.addPoorVillageHistory(poorVillageHistory);
		dequeueService.addObject(dequeue);

		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_ADD_SUCCESS, id);
	}

	/**
	 * 自然村添加
	 */
	@OperationLog(desc = "自然村添加", module = "扶贫对象管理")
	@RequestMapping("/addNaVillage")
	@ResponseBody
	public Object addNaVillage(@Valid PoorVillage poorVillage, HttpSession session) {
        Area area = poorVillage.getArea();
        if (BeanUtil.isValid(area) && !BeanUtil.isValid(area.getId())) {
            return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, "请选择行政区域");
        }

        String annual = ApplicationProperties.getAnnual();
        poorVillage.setAnnual(annual);
		poorVillage.setAddTime(new Date());
		poorVillage.setType("1");
		poorVillage.setIsDel("0");
		//贫困户数
        poorVillage.setPoor(ApplicationProperties.getPoorFamilyCount(annual,area.getId()));
        //贫困人口数
		poorVillage.setPoorNumber(ApplicationProperties.getFamilyCount(annual,area.getId()));

		if (this.poorVillageService.isExsitVillage(area.getId(), annual))
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, "该自然村已存在，不能重复添加");

		Long id = poorVillageService.addPoorVillage(poorVillage);
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_ADD_SUCCESS, id);
	}

	/**
	 * 贫困村修改
	 */
	@OperationLog(desc = "贫困村修改", module = "扶贫对象管理")
	@RequestMapping("/updatePoorVillage")
	@ResponseBody
	public Object updatePoorVillage(@Valid PoorVillage poorVillage, HttpSession session) {
		log.info("贫困村修改 id:" + poorVillage.getId());

        PoorVillage persistentPoorVillage = poorVillageService.get(poorVillage.getId());

        Area newArea = poorVillage.getArea();
        poorVillage.setIsDel(persistentPoorVillage.getIsDel());
        poorVillage.setAnnual(persistentPoorVillage.getAnnual());
        poorVillage.setType(persistentPoorVillage.getType());
        poorVillage.setStatus(persistentPoorVillage.getStatus());
        poorVillage.setAddTime(persistentPoorVillage.getAddTime());
        poorVillage.setRoad(persistentPoorVillage.getRoad());
        poorVillage.setElectrics(persistentPoorVillage.getElectrics());
        poorVillage.setLifes(persistentPoorVillage.getLifes());
        poorVillage.setBroadbands(persistentPoorVillage.getBroadbands());
        poorVillage.setDistance(persistentPoorVillage.getDistance());
        poorVillage.setUpTime(new Date());

        String annual = StringUtils.isNotBlank(poorVillage.getAnnual()) ? poorVillage.getAnnual() : ApplicationProperties.getAnnual();
        poorVillage.setPoor(ApplicationProperties.getPoorFamilyCount(annual,newArea.getId()));
        poorVillage.setPoorNumber(ApplicationProperties.getFamilyCount(annual,newArea.getId()));

        boolean flag = poorVillageService.isExsitPoorVillage(poorVillage);
        if (flag) {
            return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, "该贫困村已存在,不能重复选择");
        }

        Dequeue dequeue = new Dequeue();
        dequeue.setAnnual(annual);
        PoorVillageHistory poorVillageHistory = new PoorVillageHistory();
        BeanUtils.copyProperties(persistentPoorVillage, poorVillageHistory);
        BeanUtils.copyProperties(poorVillage, persistentPoorVillage);
        poorVillageHistory.setOriginId(poorVillage.getId());
        dequeue.setPoorVillageHistory(poorVillageHistory);
        dequeue.setOriginPoorVillage(poorVillage);
        dequeue.setAddTime(new Date());
		// 3代表信息变更
		dequeue.setChanges("3");
		poorVillageHistory.setId(null);
		poorVillageService.addPoorVillageHistory(poorVillageHistory);
		dequeueService.addObject(dequeue);

		poorVillageService.modifyObject(persistentPoorVillage);

		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_SUCCESS);
	}

	/**
	 * 自然村修改
	 */
	@OperationLog(desc = "自然村修改", module = "扶贫对象管理")
	@RequestMapping("/updateNaVillage")
	@ResponseBody
	public Object updateNaVillage(@Valid PoorVillage poorVillage) {
        PoorVillage poor = this.poorVillageService.get(poorVillage.getId());
        String annual =  StringUtils.isNotBlank(poor.getAnnual()) ? poor.getAnnual() : ApplicationProperties.getAnnual();
        boolean flag = poorVillageService.isExsitName(poorVillage.getId(), poorVillage.getName(), annual);

        if (flag) {
            return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, "该自然村已存在,不能重复选择");
        }
        Area newArea = poorVillage.getArea();
        poor.setUpTime(new Date());

		// 自然村编辑时的基本情况信息
		poor.setArea(poorVillage.getArea());
		poor.setCty(poorVillage.getCty());
		poor.setCry(poorVillage.getCry());
		poor.setVillage(poorVillage.getVillage());
		poor.setName(poorVillage.getName());
		poor.setCode(poorVillage.getCode());
		poor.setGroupNumber(poorVillage.getGroupNumber());
		poor.setFpeople(poorVillage.getFpeople());
		poor.setContact(poorVillage.getContact());
		poor.setNature(poorVillage.getNature());

		// 自然村编辑时的人口信息
		poor.setTotal(poorVillage.getTotal());
		poor.setPoor(ApplicationProperties.getPoorFamilyCount(annual,newArea.getId()));
		poor.setLowHouse(poorVillage.getLowHouse());
		poor.setFiveHouse(poorVillage.getFiveHouse());
		poor.setTotalNumber(poorVillage.getTotalNumber());
		poor.setPoorNumber(ApplicationProperties.getFamilyCount(annual,newArea.getId()));
		poor.setLowNumber(poorVillage.getLowNumber());
		poor.setFiveNumber(poorVillage.getFiveNumber());
		poor.setLessNumber(poorVillage.getLessNumber());
		poor.setWomanNumber(poorVillage.getWomanNumber());
		poor.setRemnantNumber(poorVillage.getRemnantNumber());
		poor.setLabourNumber(poorVillage.getLabourNumber());
		poor.setGooutNumber(poorVillage.getGooutNumber());

		// 自然村编辑时的生产生活条件
		poor.setDistance(poorVillage.getDistance());
		poor.setRoad(poorVillage.getRoad());
		poor.setElectrics(poorVillage.getElectrics());
		poor.setLifes(poorVillage.getLifes());
		poor.setBroadbands(poorVillage.getBroadbands());
		
		poorVillageService.modifyObject(poor);
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_SUCCESS);
	}

	/**
	 * 贫困村删除
	 * 
	 * 20171129: 贫困村页面删除时调用此方法
	 */
	@OperationLog(desc = "贫困村删除", module = "扶贫对象管理")
	@RequestMapping("/deletePoorVillage")
	@ResponseBody
	public Object deletePoorVillage(Long id, HttpSession session) {
		PoorVillage persistentPoorVillage = this.poorVillageService.get(id);
		persistentPoorVillage.setNature("非贫困村");

		Dequeue dequeue = new Dequeue();
		dequeue.setAnnual(ApplicationProperties.getAnnual());
		PoorVillageHistory poorVillageHistory = new PoorVillageHistory();
		BeanUtils.copyProperties(persistentPoorVillage, poorVillageHistory);
		poorVillageHistory.setOriginId(id);
		dequeue.setPoorVillageHistory(poorVillageHistory);
		dequeue.setOriginPoorVillage(persistentPoorVillage);
		dequeue.setAddTime(new Date());
		// 4代表删除
		dequeue.setChanges("4");
		poorVillageHistory.setId(null);
		poorVillageService.addPoorVillageHistory(poorVillageHistory);
		dequeueService.addObject(dequeue);

		persistentPoorVillage.setType("1");
		poorVillageService.modifyPoorVillage(persistentPoorVillage);
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_DELETE_SUCCESS);
	}

	/**
	 * 自然村删除
	 * 
	 * 20171129: 页面自然村删除时调用此方法
	 */
	@OperationLog(desc = "自然村删除", module = "扶贫对象管理")
	@RequestMapping("/deletePoorVillages")
	@ResponseBody
	public Object deletePoorVillages(Long id) {
		PoorVillage persistentPoorVillage = this.poorVillageService.get(id);

		// XXX 如果已属于贫困村则无法在此删除
		// 以下为新添加
		if ("0".equals(persistentPoorVillage.getType())) {
			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, " 当前记录已属于贫困村，无法在此删除 ", "failure");
		}
		// end
		persistentPoorVillage.setIsDel("1");
		poorVillageService.modifyPoorVillage(persistentPoorVillage);
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_DELETE_SUCCESS);
	}

	/**
	 * 贫困村or自然村 查看详情（根据ID）
	 *
	 * @return
	 */
	@OperationLog(desc = "村详情查看", module = "扶贫对象管理")
	@RequestMapping("/getPoorVillage")
	@ResponseBody
	public Object getPoorVillage(Long id) {
		PoorVillage poorVillage = this.poorVillageService.get(id);
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, poorVillage);
	}

	/**
	 * （根据ID）扶贫单位根据id查出贫困村
	 *
	 * @return
	 */
	// @OperationLog(desc = "扶贫单位根据id查出贫困村", module = "扶贫对象管理")
	@RequestMapping("/getPoorVillages")
	@ResponseBody
	public Object getPoorVillages(Long id) {
		// List<PoorVillage> poorVillage =
		// this.poorVillageService.poorVillages(id);

		List<PoorVillage> poorVillage = poorVillageService.getPoorVillages(id);
		Iterator<PoorVillage> iterator = poorVillage.iterator();
		while (iterator.hasNext()) {
			PoorVillage next = iterator.next();
			if ("1".equals(next.getIsDel())) {
				iterator.remove();
			}
		}
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, poorVillage);
	}

	/**
	 * 自然村条件模糊查询
	 */
	@OperationLog(desc = "自然村条件模糊查询", module = "扶贫对象管理")
	@RequestMapping("/queryNaVague")
	@ResponseBody
	public Object queryNaVague(Integer pageNo, Integer pageSize, @Valid PoorVillage poorVillage, String year,
		HttpServletRequest req) {
		if (pageNo == null || pageNo < 1) {
			pageNo = 1;
		}
		if (pageSize == null || pageSize < 1) {
			pageSize = 10;
		}
		McUser user = (McUser) req.getSession().getAttribute("user");
		Pager pager = this.poorVillageService.getNaPagers(pageNo, pageSize, poorVillage, year, user);
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, pager);
	}

	/**
	 * 贫困村条件模糊查询
	 */
//	@OperationLog(desc = "贫困村条件模糊查询", module = "扶贫对象管理")
	@RequestMapping("/queryPoVague")
	@ResponseBody
	public Object queryPoVague(Integer pageNo, Integer pageSize, @Valid PoorVillage poorVillage, @RequestParam("year") String year,
		HttpServletRequest req) {
		if (pageNo == null || pageNo < 1) {
			pageNo = 1;
		}
		if (pageSize == null || pageSize < 1) {
			pageSize = 10;
		}
		McUser user = (McUser) req.getSession().getAttribute("user");
		Pager pager = this.poorVillageService.getPoPager(pageNo, pageSize, poorVillage, year, user);
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, pager);
	}

	/**
	 * 自然村管理导出
	 */
	@OperationLog(desc = "自然村管理导出", module = "扶贫对象管理")
	@RequestMapping("/exportNaVillage")
	@ResponseBody
	public Object exportNaVillage(@Valid PoorVillage poorVillage, HttpServletRequest req,
		@RequestParam(name = "year", required = false) String year, HttpSession session, HttpServletResponse response) {
		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));
		try {
			HSSFWorkbook wb = poorVillageService.exportNaVillage(year, poorVillage, user, req);

			response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("自然村管理表", "UTF-8") + ".xls");
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");

			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
			wb.write(bufferedOutputStream);
			bufferedOutputStream.close();

			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_EXPORT_SUCCESS);
		} catch (IOException e) {
			e.printStackTrace();
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, CommonConstant.MSG_EXPORT_FAIL);
		}
	}

	/**
	 * 贫困村管理导出
	 */
	@OperationLog(desc = "贫困村管理导出", module = "扶贫对象管理")
	@RequestMapping("/exportPoVillage")
	@ResponseBody
	public Object exportPoVillage(@Valid PoorVillage poorVillage, HttpServletRequest req,
		@RequestParam(name = "year", required = false) String year, HttpSession session, HttpServletResponse response) {
		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));
		try {
			HSSFWorkbook wb = poorVillageService.exportPoVillage(year, poorVillage, user, req);

			response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("贫困村管理表", "UTF-8") + ".xls");
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");

			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
			wb.write(bufferedOutputStream);
			bufferedOutputStream.close();

			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_EXPORT_SUCCESS);
		} catch (IOException e) {
			e.printStackTrace();
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, CommonConstant.MSG_EXPORT_FAIL);
		}
	}

	/**
	 * 自然村管理导出
	 */
	@OperationLog(desc = "自然村查询导出", module = "扶贫对象管理")
	@RequestMapping("/exportNaVillageZ")
	@ResponseBody
	public Object exportNaVillageZ(@Valid PoorVillage poorVillage, HttpServletRequest req,
		@RequestParam(name = "year", required = false) String year, HttpSession session, HttpServletResponse response) {
		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));
		try {
			HSSFWorkbook wb = poorVillageService.exportNaVillageZ(year, poorVillage, user, req);

			response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("自然村查询表", "UTF-8") + ".xls");
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");

			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
			wb.write(bufferedOutputStream);
			bufferedOutputStream.close();

			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_EXPORT_SUCCESS);
		} catch (IOException e) {
			e.printStackTrace();
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, CommonConstant.MSG_EXPORT_FAIL);
		}
	}

	/**
	 * 贫困村查询导出
	 */
	@OperationLog(desc = "贫困村查询导出", module = "扶贫对象管理")
	@RequestMapping("/exportPoVillageZ")
	@ResponseBody
	public Object exportPoVillageZ(@Valid PoorVillage poorVillage, HttpServletRequest req,
		@RequestParam(name = "year", required = false) String year, HttpSession session, HttpServletResponse response) {
		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));
		try {
			HSSFWorkbook wb = poorVillageService.exportPoVillageZ(year, poorVillage, user, req);

			response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("贫困村查询表", "UTF-8") + ".xls");
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");

			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
			wb.write(bufferedOutputStream);
			bufferedOutputStream.close();

			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_EXPORT_SUCCESS);
		} catch (IOException e) {
			e.printStackTrace();
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, CommonConstant.MSG_EXPORT_FAIL);
		}
	}

	/**
	 * 首页 贫困村个数
	 */
	// @OperationLog(desc = "贫困村个数", module = "首页统计")
	@RequestMapping("/NemberPoorVillages")
	@ResponseBody
	public Object NemberPoorVillages(HttpSession session) {
		List unitsN = new ArrayList<>(0);
		Element element = manager.getCache("indexStatistics").get("NemberPoorVillages");
		if(element != null) {
			unitsN =  (List) element.getObjectValue();
		} else {
			unitsN = poorVillageService.unitsNr();
		}
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, unitsN);
		// return new ResponseBean(CommonConstant.SUCCESS_CODE_200,
		// CommonConstant.MSG_FIND_SUCCESS, new ArrayList<>());
	}

	/**
	 * 贫困村导入
	 * 
	 * @param file
	 * @param questId
	 * @param session
	 * @return
	 */
	@OperationLog(desc = "贫困村导入", module = "扶贫对象管理")
	@RequestMapping(value = "/insert", method = RequestMethod.POST)
	@ResponseBody
	public Object addPoorVillageExc(String file, Long questId, HttpSession session) {
		long dataTimeS = System.currentTimeMillis();
		try {
			McUser mcUser = userService
				.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));
			// 开始导入
			String result = this.poorVillageService.adduploadFile(file, session, mcUser);
			long dataTimeE = System.currentTimeMillis();
			log.info(dataTimeE - dataTimeS + "S>>>>>>>>>>>>>>>贫困村导入 总耗时");

			// 路径
			if ("NO_URL".equals(result)) {
				return new ResponseBean(CommonConstant.FAIL_CODE_400, CommonConstant.MSG_FILE_NOURL);
			}
			// 导入错误
			if (!"T".equals(result)) {
				return new ResponseBean(CommonConstant.SUCCESS_CODE_300, CommonConstant.MSG_IMPORT_ERROR, result);
			}
			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_IMPORT_SUCCESS);
		} catch (Exception e) {
			LogUtil.logException("PoorVillageController import has exception:", e);
			e.printStackTrace();
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, CommonConstant.MSG_IMPORT_ERROR);
		}
	}

	/**
	 * 贫困村识别标准统计
	 */
	@OperationLog(desc = "贫困村识别标准统计查询 ", module = "统计分析")
	@RequestMapping("/poorVillageStatistics")
	@ResponseBody
	public Object poorVilageStatistics(Integer pageNo, Integer pageSize, @RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String status, HttpSession session) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		Pager page = poorVillageService.poorVillageStatistics(user, pageNo, pageSize, year, country, village, status);

		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, page);
	}

	/**
	 * 贫困村发展方向分类统计
	 */
	@OperationLog(desc = "贫困村发展方向分类统计查询", module = "统计分析")
	@RequestMapping("/poorVilageDevelopmentclass")
	@ResponseBody
	public Object poorVilageDevelopmentclass(Integer pageNo, Integer pageSize,
		@RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		Pager page = poorVillageService.poorVilageDevelopmentclass(user, pageNo, pageSize, year, country, village, type);

		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, page);
	}

	/**
	 * 贫困村地形地貌分类统计
	 */
	@OperationLog(desc = "贫困村地形地貌分类统计查询", module = "统计分析")
	@RequestMapping("/poorVilageLandformclass")
	@ResponseBody
	public Object poorVilageLandformclass(Integer pageNo, Integer pageSize,
		@RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		Pager page = poorVillageService.poorVilageLandformclass(user, pageNo, pageSize, year, country, village, type);

		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, page);
	}

	/**
	 * 贫困村识别标准统计excel导出
	 */
	@OperationLog(desc = "贫困村识别标准统计excel导出 ", module = "统计分析")
	@RequestMapping("/exportPoorVillageStatistics")
	@ResponseBody
	public Object exportPoorVillageStatistics(@RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String status, HttpSession session, HttpServletResponse response) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		HSSFWorkbook wb = poorVillageService.exportPoorVillageStatistics(user, null, null, year, country, village, status);
		try {

			response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("贫困村识别标准统计表", "UTF-8") + ".xls");
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");

			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
			wb.write(bufferedOutputStream);
			bufferedOutputStream.close();

			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_EXPORT_SUCCESS);
		} catch (IOException e) {
			e.printStackTrace();
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, CommonConstant.MSG_EXPORT_FAIL);
		}
	}

	/**
	 * 贫困村发展方向分类统计excel导出
	 */
	@OperationLog(desc = "贫困村发展方向分类统计excel导出", module = "统计分析")
	@RequestMapping("/exportDevelopmentclass")
	@ResponseBody
	public Object exportDevelopmentclass(@RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session, HttpServletResponse response) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		HSSFWorkbook wb = poorVillageService.exportDevelopmentclass(user, null, null, year, country, village, type);
		try {

			response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("贫困村发展方向分类统计表", "UTF-8") + ".xls");
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");

			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
			wb.write(bufferedOutputStream);
			bufferedOutputStream.close();

			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_EXPORT_SUCCESS);
		} catch (IOException e) {
			e.printStackTrace();
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, CommonConstant.MSG_EXPORT_FAIL);
		}
	}

	/**
	 * 贫困村地形地貌分类统计excel导出
	 */
	@OperationLog(desc = "贫困村地形地貌分类统计excel导出", module = "统计分析")
	@RequestMapping("/exportLandformclass")
	@ResponseBody
	public Object exportLandformclass(@RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session, HttpServletResponse response) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		HSSFWorkbook wb = poorVillageService.exportLandformclass(user, null, null, year, country, village, type);
		try {

			response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("贫困村地形地貌分类统计表", "UTF-8") + ".xls");
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");

			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
			wb.write(bufferedOutputStream);
			bufferedOutputStream.close();

			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_EXPORT_SUCCESS);
		} catch (IOException e) {
			e.printStackTrace();
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, CommonConstant.MSG_EXPORT_FAIL);
		}
	}

	/**
	 * 贫困村土地资源情况统计表
	 */
	@OperationLog(desc = "贫困村土地资源情况统计表查询", module = "统计分析")
	@RequestMapping("/poorVilageLand")
	@ResponseBody
	public Object poorVilageLand(Integer pageNo, Integer pageSize, @RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		Pager list = poorVillageService.poorVilageLand(user, pageNo, pageSize, year, country, village, type);

		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, list);
	}

	/**
	 * 贫困村土地资源情况统计表excel导出
	 */
	@OperationLog(desc = "贫困村土地资源情况统计表导出", module = "统计分析")
	@RequestMapping("/exportPoorVilageLand")
	@ResponseBody
	public Object exportPoorVilageLand(@RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session, HttpServletResponse response) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		HSSFWorkbook wb = poorVillageService.exportPoorVilageLand(user, null, null, year, country, village, type);
		try {

			response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("贫困村土地资源情况统计表", "UTF-8") + ".xls");
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");

			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
			wb.write(bufferedOutputStream);
			bufferedOutputStream.close();

			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_EXPORT_SUCCESS);
		} catch (IOException e) {
			e.printStackTrace();
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, CommonConstant.MSG_EXPORT_FAIL);
		}
	}

	/**
	 * 贫困村村官和党员情况统计表
	 */
	@OperationLog(desc = "贫困村村官和党员情况统计表查询", module = "统计分析")
	@RequestMapping("/poorVilageOfficialsAndMembers")
	@ResponseBody
	public Object poorVilageOfficialsAndMembers(Integer pageNo, Integer pageSize,
		@RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		Pager list = poorVillageService.poorVilageOfficialsAndMembers(user, pageNo, pageSize, year, country, village, type);

		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, list);
	}

	/**
	 * 贫困村村官和党员情况统计表excel导出
	 */
	@OperationLog(desc = "贫困村村官和党员情况统计表导出", module = "统计分析")
	@RequestMapping("/exportPoorVilageOfficialsAndMembers")
	@ResponseBody
	public Object exportPoorVilageOfficialsAndMembers(@RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session, HttpServletResponse response) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		HSSFWorkbook wb = poorVillageService.exportPoorVilageOfficialsAndMembers(user, null, null, year, country, village, type);
		try {

			response.setHeader("Content-Disposition",
				"attachment;filename=" + URLEncoder.encode("贫困村村官和党员情况统计表", "UTF-8") + ".xls");
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");

			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
			wb.write(bufferedOutputStream);
			bufferedOutputStream.close();

			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_EXPORT_SUCCESS);
		} catch (IOException e) {
			e.printStackTrace();
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, CommonConstant.MSG_EXPORT_FAIL);
		}
	}

	/**
	 * 贫困村开展乡村旅游情况统计表
	 */
	@OperationLog(desc = "贫困村开展乡村旅游情况统计表查询", module = "统计分析")
	@RequestMapping(value = "/ruraiTourism", method = RequestMethod.POST)
	@ResponseBody
	public Object ruralTourism(Integer pageNo, Integer pageSize, @RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session) {
		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));
		Pager pager = poorVillageService.ruralTourism(user, pageNo, pageSize, year, country, village, type);
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, pager);
	}

	/**
	 * 贫困村卫计情况统计表
	 */
	@OperationLog(desc = "贫困村卫计情况统计表查询", module = "统计分析")
	@RequestMapping(value = "/satelliteMonitor", method = RequestMethod.POST)
	@ResponseBody
	public Object satelliteMonitor(Integer pageNo, Integer pageSize, @RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session) {
		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));
		Pager pager = poorVillageService.satelliteMonitor(user, pageNo, pageSize, year, country, village, type);
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, pager);
	}

	/**
	 * 贫困村开展乡村旅游情况统计表excel导出
	 */
	@OperationLog(desc = "贫困村开展乡村旅游情况统计表excel导出", module = "统计分析")
	@RequestMapping("/exportruraiTourism")
	@ResponseBody
	public Object exportruraiTourism(@RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session, HttpServletResponse response) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		HSSFWorkbook wb = poorVillageService.exportruraiTourism(user, null, null, year, country, village, type);
		try {

			response.setHeader("Content-Disposition",
				"attachment;filename=" + URLEncoder.encode("贫困村开展乡村旅游情况统计表", "UTF-8") + ".xls");
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");

			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
			wb.write(bufferedOutputStream);
			bufferedOutputStream.close();

			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_EXPORT_SUCCESS);
		} catch (IOException e) {
			e.printStackTrace();
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, CommonConstant.MSG_EXPORT_FAIL);
		}
	}

	/**
	 * 贫困村卫计情况统计表excel导出
	 */
	@OperationLog(desc = "贫困村卫计情况统计表excel导出", module = "统计分析")
	@RequestMapping("/exportsatelliteMonitor")
	@ResponseBody
	public Object exportsatelliteMonitor(@RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session, HttpServletResponse response) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		HSSFWorkbook wb = poorVillageService.exportsatelliteMonitor(user, null, null, year, country, village, type);
		try {

			response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("贫困村卫计情况统计表", "UTF-8") + ".xls");
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");

			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
			wb.write(bufferedOutputStream);
			bufferedOutputStream.close();

			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_EXPORT_SUCCESS);
		} catch (IOException e) {
			e.printStackTrace();
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, CommonConstant.MSG_EXPORT_FAIL);
		}
	}

	/**
	 * 贫困村文化建设情况统计表
	 */
//	@OperationLog(desc = "贫困村文化建设情况统计表查询", module = "统计分析")
	@RequestMapping(value = "/construction", method = RequestMethod.POST)
	@ResponseBody
	public Object construction(Integer pageNo, Integer pageSize, @RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session) {
		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));
		Pager pager = poorVillageService.construction(user, pageNo, pageSize, year, country, village, type);
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, pager);
	}

	/**
	 * 贫困村文化建设情况统计表excel导出
	 */
	@OperationLog(desc = "贫困村文化建设情况统计表excel导出", module = "统计分析")
	@RequestMapping("/exportconstruction")
	@ResponseBody
	public Object exportconstruction(@RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session, HttpServletResponse response) {
		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));
		HSSFWorkbook wb = poorVillageService.exportconstruction(user, null, null, year, country, village, type);
		try {
			response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("贫困村文化建设情况统计表", "UTF-8") + ".xls");
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");
			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
			wb.write(bufferedOutputStream);
			bufferedOutputStream.close();
			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_EXPORT_SUCCESS);
		} catch (IOException e) {
			e.printStackTrace();
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, CommonConstant.MSG_EXPORT_FAIL);
		}
	}

	/**
	 * 贫困村信息化建设情况统计表
	 */
	@OperationLog(desc = "贫困村信息化建设情况统计表查询", module = "统计分析")
	@RequestMapping(value = "/information", method = RequestMethod.POST)
	@ResponseBody
	public Object information(Integer pageNo, Integer pageSize, @RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session) {
		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));
		Pager pager = poorVillageService.information(user, pageNo, pageSize, year, country, village, type);
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, pager);
	}

	/**
	 * 证件号码重复统计表
	 */
	@SuppressWarnings("all")
//	@OperationLog(desc = "证件号码重复统计表查询", module = "统计分析")
	@RequestMapping(value = "/duplicateIDnumber", method = RequestMethod.POST)
	@ResponseBody
	public Object duplicateIDnumber(Integer pageNo, Integer pageSize, @RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village, HttpSession session) {
		
		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));
		Pager pager = poorFamilyService.complexDuplicateIDNumberStatistics(pageNo, pageSize, year, country, user);
		
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, pager);
	}

	/**
	 * 贫困村信息化建设情况统计表excel导出
	 */
//	@OperationLog(desc = "贫困村信息化建设情况统计表excel导出", module = "统计分析")
	@RequestMapping("/exportinformation")
	@ResponseBody
	public Object exportinformation(@RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session, HttpServletResponse response) {
		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));
		HSSFWorkbook wb = poorVillageService.exportinformation(user, null, null, year, country, village, type);
		try {
			response.setHeader("Content-Disposition",
				"attachment;filename=" + URLEncoder.encode("贫困村信息化建设情况统计表", "UTF-8") + ".xls");
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");
			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
			wb.write(bufferedOutputStream);
			bufferedOutputStream.close();
			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_EXPORT_SUCCESS);
		} catch (IOException e) {
			e.printStackTrace();
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, CommonConstant.MSG_EXPORT_FAIL);
		}
	}

	/**
	 * 证件号码重复统计表excel导出
	 */
//	@OperationLog(desc = "证件号码重复统计表excel导出", module = "统计分析")
	@RequestMapping("/duplicateId")
	@ResponseBody
	@SuppressWarnings("all")
	public Object duplicateId(@RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session, HttpServletResponse response) {
		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));
		
		HSSFWorkbook workbook = poorFamilyService.complexExportDuplicateIDNumberStatistics(1, 5000, year, country, user);
		
		try {
			response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("证件号码重复统计表", "UTF-8") + ".xls");
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");
			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
			workbook.write(bufferedOutputStream);
			bufferedOutputStream.close();
			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_EXPORT_SUCCESS);
		} catch (IOException e) {
			e.printStackTrace();
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, CommonConstant.MSG_EXPORT_FAIL);
		}
	}

	/**
	 * 贫困村人口状况统计
	 */
//	@OperationLog(desc = "贫困村人口状况统计", module = "统计分析")
	@RequestMapping("/pvcStatistics")
	@ResponseBody
	public Object pvcStatistics(Integer pageNo, Integer pageSize, @RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String status, HttpSession session) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		Pager page = poorVillageService.pvcStatistics(user, pageNo, pageSize, year, country, village, status);

		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, page);
	}

	/**
	 * 贫困村人口状况统计excel导出
	 */
	@OperationLog(desc = "贫困村人口状况统计excel导出", module = "统计分析")
	@RequestMapping("/exportPvcStatistics")
	@ResponseBody
	public Object exportPvcStatistics(Integer pageNo, Integer pageSize, @RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String status, HttpSession session, HttpServletResponse response) {
		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));
		HSSFWorkbook wb = poorVillageService.exportPvcStatistics(user, pageNo, pageSize, year, country, village, status);
		try {
			response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("贫困村人口状况统计表", "UTF-8") + ".xls");
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");
			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
			wb.write(bufferedOutputStream);
			bufferedOutputStream.close();
			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_EXPORT_SUCCESS);
		} catch (IOException e) {
			e.printStackTrace();
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, CommonConstant.MSG_EXPORT_FAIL);
		}
	}

	/**
	 * 贫困村道路硬化及通班车情况统计表
	 */
	@OperationLog(desc = "贫困村道路硬化及通班车情况统计表查询", module = "统计分析")
	@RequestMapping("/poorVilageRoad")
	@ResponseBody
	public Object poorVilageRoad(Integer pageNo, Integer pageSize, @RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		Pager list = poorVillageService.poorVilageRoad(user, pageNo, pageSize, year, country, village, type);

		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, list);
	}

	/**
	 * 贫困村道路硬化及通班车情况统计表excel导出
	 */
	@OperationLog(desc = "贫困村道路硬化及通班车情况统计表导出", module = "统计分析")
	@RequestMapping("/exportPoorVilageRoad")
	@ResponseBody
	public Object exportPoorVilageRoad(@RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session, HttpServletResponse response) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		HSSFWorkbook wb = poorVillageService.exportPoorVilageRoad(user, null, null, year, country, village, type);
		try {

			response.setHeader("Content-Disposition",
				"attachment;filename=" + URLEncoder.encode("贫困村道路硬化及通班车情况统计表", "UTF-8") + ".xls");
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");

			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
			wb.write(bufferedOutputStream);
			bufferedOutputStream.close();

			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_EXPORT_SUCCESS);
		} catch (IOException e) {
			e.printStackTrace();
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, CommonConstant.MSG_EXPORT_FAIL);
		}
	}

	/**
	 * 贫困村饮水情况统计表
	 */
	@OperationLog(desc = "贫困村饮水情况统计表查询", module = "统计分析")
	@RequestMapping("/poorVilageWater")
	@ResponseBody
	public Object poorVilageWater(Integer pageNo, Integer pageSize, @RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		Pager list = poorVillageService.poorVilageWater(user, pageNo, pageSize, year, country, village, type);

		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, list);
	}

	/**
	 * 贫困村饮水情况统计表excel导出
	 */
	@OperationLog(desc = "贫困村饮水情况统计表导出", module = "统计分析")
	@RequestMapping("/exportPoorVilageWater")
	@ResponseBody
	public Object exportPoorVilageWater(@RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session, HttpServletResponse response) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		HSSFWorkbook wb = poorVillageService.exportPoorVilageWater(user, null, null, year, country, village, type);
		try {

			response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("贫困村饮水情况统计表", "UTF-8") + ".xls");
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");

			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
			wb.write(bufferedOutputStream);
			bufferedOutputStream.close();

			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_EXPORT_SUCCESS);
		} catch (IOException e) {
			e.printStackTrace();
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, CommonConstant.MSG_EXPORT_FAIL);
		}
	}

	/**
	 * 贫困村危房改造情况统计表
	 */
	@OperationLog(desc = "贫困村危房改造情况统计表查询", module = "统计分析")
	@RequestMapping("/poorVilageDanger")
	@ResponseBody
	public Object poorVilageDanger(Integer pageNo, Integer pageSize, @RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		Pager list = poorVillageService.poorVilageDanger(user, pageNo, pageSize, year, country, village, type);

		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, list);
	}

	/**
	 * 贫困村危房改造情况统计表excel导出
	 */
	@OperationLog(desc = "贫困村危房改造情况统计表导出", module = "统计分析")
	@RequestMapping("/exportPoorVilageDanger")
	@ResponseBody
	public Object exportPoorVilageDanger(@RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session, HttpServletResponse response) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		HSSFWorkbook wb = poorVillageService.exportPoorVilageDanger(user, null, null, year, country, village, type);
		try {

			response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("贫困村危房改造情况统计表", "UTF-8") + ".xls");
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");

			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
			wb.write(bufferedOutputStream);
			bufferedOutputStream.close();

			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_EXPORT_SUCCESS);
		} catch (IOException e) {
			e.printStackTrace();
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, CommonConstant.MSG_EXPORT_FAIL);
		}
	}

	/**
	 * 贫困村参加社会保险分组情况统计表
	 */
	@OperationLog(desc = "贫困村参加社会保险分组情况统计表查询", module = "统计分析")
	@RequestMapping("/poorVilageInsurance")
	@ResponseBody

	public Object poorVilageInsurance(Integer pageNo, Integer pageSize, @RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		Pager list = poorVillageService.poorVilageInsurance(user, pageNo, pageSize, year, country, village, type);

		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, list);
	}

	/**
	 * 贫困村参加社会保险分组情况统计表excel导出
	 */
	@OperationLog(desc = "贫困村参加社会保险分组情况统计表导出", module = "统计分析")
	@RequestMapping("/exportPoorVilageInsurance")
	@ResponseBody
	public Object exportPoorVilageInsurance(@RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session, HttpServletResponse response) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		HSSFWorkbook wb = poorVillageService.exportPoorVilageInsurance(user, null, null, year, country, village, type);
		try {

			response.setHeader("Content-Disposition",
				"attachment;filename=" + URLEncoder.encode("贫困村参加社会保险分组情况统计表", "UTF-8") + ".xls");
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");

			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
			wb.write(bufferedOutputStream);
			bufferedOutputStream.close();

			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_EXPORT_SUCCESS);
		} catch (IOException e) {
			e.printStackTrace();
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, CommonConstant.MSG_EXPORT_FAIL);
		}
	}

	/**
	 * 贫困村特色产业增收情况统计表
	 */
	@OperationLog(desc = "贫困村特色产业增收情况统计表查询", module = "统计分析")
	@RequestMapping("/poorVilageCharacteristic")
	@ResponseBody
	public Object poorVilageCharacteristic(Integer pageNo, Integer pageSize,
		@RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		Pager list = poorVillageService.poorVilageCharacteristic(user, pageNo, pageSize, year, country, village, type);

		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, list);
	}

	/**
	 * 贫困村特色产业增收情况统计表excel导出
	 */
	@OperationLog(desc = "贫困村特色产业增收情况统计表导出", module = "统计分析")
	@RequestMapping("/exportPoorVilageCharacteristic")
	@ResponseBody
	public Object exportPoorVilageCharacteristic(@RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session, HttpServletResponse response) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		HSSFWorkbook wb = poorVillageService.exportPoorVilageCharacteristic(user, null, null, year, country, village, type);
		try {

			response.setHeader("Content-Disposition",
				"attachment;filename=" + URLEncoder.encode("贫困村特色产业增收情况统计表", "UTF-8") + ".xls");
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");

			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
			wb.write(bufferedOutputStream);
			bufferedOutputStream.close();

			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_EXPORT_SUCCESS);
		} catch (IOException e) {
			e.printStackTrace();
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, CommonConstant.MSG_EXPORT_FAIL);
		}
	}

	/**
	 * 贫困人口净减少统计表
	 */
	@OperationLog(desc = "贫困人口净减少统计表查询", module = "统计分析")
	@RequestMapping(value = "/poordecreaseofPopulation", method = RequestMethod.POST)
	@ResponseBody
	public Object poordecreaseofPopulation(Integer pageNo, Integer pageSize,
		@RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session) {
		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));
		Pager pager = poorVillageService.poordecreaseofPopulation(user, pageNo, pageSize, year, country, village, type);
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, pager);
	}

	/**
	 * 贫困人口净减少统计表excel导出
	 */
	@OperationLog(desc = "贫困人口净减少统计表excel导出", module = "统计分析")
	@RequestMapping("/exportpoordecreaseofPopulation")
	@ResponseBody
	public Object exportpoordecreaseofPopulation(@RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String type, HttpSession session, HttpServletResponse response) {
		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));
		HSSFWorkbook wb = poorVillageService.exportpoordecreaseofPopulation(user, null, null, year, country, village, type);
		try {
			response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("贫困人口净减少统计表", "UTF-8") + ".xls");
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");
			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
			wb.write(bufferedOutputStream);
			bufferedOutputStream.close();
			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_EXPORT_SUCCESS);
		} catch (IOException e) {
			e.printStackTrace();
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, CommonConstant.MSG_EXPORT_FAIL);
		}
	}

	/**
	 * 贫困村年人均收入分组情况统计
	 */
	@OperationLog(desc = "贫困村年人均收入分组情况统计", module = "统计分析")
	@RequestMapping("/perIncomeStatistics")
	@ResponseBody
	public Object perIncomeStatistics(Integer pageNo, Integer pageSize, @RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String status, HttpSession session) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		Pager page = poorVillageService.perIncomeStatistics(user, pageNo, pageSize, year, country, village, status);

		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, page);
	}

	/**
	 * 贫困村年人均收入分组情况统计excel导出
	 */
	@OperationLog(desc = "贫困村年人均收入分组情况统计excel导出", module = "统计分析")
	@RequestMapping("/exportPerIncomeStatistics")
	@ResponseBody
	public Object exportPerIncomeStatistics(@RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String status, HttpSession session, HttpServletResponse response) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		HSSFWorkbook wb = poorVillageService.exportPerIncomeStatistics(user, null, null, year, country, village, status);
		try {

			response.setHeader("Content-Disposition",
				"attachment;filename=" + URLEncoder.encode("贫困村年人均收入分组情况统计表", "UTF-8") + ".xls");
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");

			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
			wb.write(bufferedOutputStream);
			bufferedOutputStream.close();

			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_EXPORT_SUCCESS);
		} catch (IOException e) {
			e.printStackTrace();
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, CommonConstant.MSG_EXPORT_FAIL);
		}
	}

	/**
	 * 贫困村村集体经济收入分组情况统计
	 */
	@OperationLog(desc = "贫困村村集体经济收入分组情况统计", module = "统计分析")
	@RequestMapping("/villageIncomeStatistics")
	@ResponseBody
	public Object villageIncomeStatistics(Integer pageNo, Integer pageSize,
		@RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String status, HttpSession session) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		Pager page = poorVillageService.villageIncomeStatistics(user, pageNo, pageSize, year, country, village, status);

		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, page);
	}

	/**
	 * 贫困村村集体经济收入分组情况统计excel导出
	 */
	@OperationLog(desc = "贫困村村集体经济收入分组情况统计excel导出", module = "统计分析")
	@RequestMapping("/exportVillageIncomeStatistics")
	@ResponseBody
	public Object exportVillageIncomeStatistics(@RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String status, HttpSession session, HttpServletResponse response) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		HSSFWorkbook wb = poorVillageService.exportVillageIncomeStatistics(user, null, null, year, country, village, status);
		try {

			response.setHeader("Content-Disposition",
				"attachment;filename=" + URLEncoder.encode("贫困村村集体经济收入分组情况统计表", "UTF-8") + ".xls");
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");

			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
			wb.write(bufferedOutputStream);
			bufferedOutputStream.close();

			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_EXPORT_SUCCESS);
		} catch (IOException e) {
			e.printStackTrace();
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, CommonConstant.MSG_EXPORT_FAIL);
		}
	}

	/**
	 * 贫困村未脱贫人口情况统计
	 */
	@OperationLog(desc = "贫困村未脱贫人口情况统计", module = "统计分析")
	@RequestMapping("/wtpStatistics")
	@ResponseBody
	public Object wtpStatistics(Integer pageNo, Integer pageSize, @RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String status, HttpSession session) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		Pager page = poorVillageService.wtpStatistics(user, pageNo, pageSize, year, country, village, status);

		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, page);
	}

	/**
	 * 贫困村未脱贫人口情况统计excel导出
	 */
	@OperationLog(desc = "贫困村未脱贫人口情况统计excel导出", module = "统计分析")
	@RequestMapping("/exportWtpStatistics")
	@ResponseBody
	public Object exportWtpStatistics(@RequestParam(name = "year", required = false) String year,
		@RequestParam(name = "country", required = false) String country,
		@RequestParam(name = "village", required = false) String village,
		@RequestParam(name = "type", required = false) String status, HttpSession session, HttpServletResponse response) {

		McUser user = userService.retrieveUserByUsername((String) session.getAttribute(CommonRedisConstant.REDIS_KEY_LOGIN_USER));

		HSSFWorkbook wb = poorVillageService.exportWtpStatistics(user, null, null, year, country, village, status);
		try {

			response.setHeader("Content-Disposition",
				"attachment;filename=" + URLEncoder.encode("贫困村未脱贫人口情况统计表", "UTF-8") + ".xls");
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");

			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
			wb.write(bufferedOutputStream);
			bufferedOutputStream.close();

			return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_EXPORT_SUCCESS);
		} catch (IOException e) {
			e.printStackTrace();
			return new ResponseBean(CommonConstant.EXCEPTION_CODE_500, CommonConstant.MSG_EXPORT_FAIL);
		}
	}

	/**
	 * 获取指定id的贫困村历史记录
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping("/getPoorVillageHistory")
	@ResponseBody
	public Object getPoorVillageHistory(Long id) {

		PoorVillageHistory poorVillageHistory = poorVillageService.getPoorVillageHistory(id);
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, poorVillageHistory);
	}



    /**
     *  更新贫困村中的贫困户数和贫困人口数字段
     */
    @RequestMapping("/maintainTablePoorVillage")
    @ResponseBody
    public Object updatePoorFamilyCountAndFamilyCountOfPoorVillage(String year) {

        String annual = StringUtils.isNotBlank(year) ? year : ApplicationProperties.getAnnual();
        List<Area> allVillage = areaService.getALLVillage();
        Set<Long> ids = new HashSet<>();
        Map<Long,String> areaMap = new HashMap<>();
        for(Area e : allVillage) {
            ids.add(e.getId());
            areaMap.put(e.getId(),e.getArea());
        }

        Map<String,String> result = new HashMap<>();
        for(Long id : ids) {
            String poorFamilyCount = tableMaintenance.updatePoorFamilyCount(annual, id);
            String familyCount = tableMaintenance.updateFamilyCount(annual,id);
            result.put(id.toString()+"_"+areaMap.get(id),"贫困户数：" + poorFamilyCount + ", 贫困人口数：" + familyCount);
        }

        return new ResponseBean(CommonConstant.SUCCESS_CODE_200,"贫困村表字段维护成功",result);
    }
}
